<?php
namespace app\index\model;

use think\Model;
use think\Db;
class Department extends Model
{
    protected $table = 'department';
    //自定义初始化
    protected function initialize()
    {
        //需要调用`Model`的`initialize`方法
        parent::initialize();
        //TODO:自定义的初始化
    }
    //查询部门信息列表
    //$where为搜索条件数组
    public function get_department_list($where,$page=1,$lists=10){
    	
    	$pagestart=($page-1)*$lists;
    	$arr=Db::table($this->table)->alias('d')
    	->join("employee e","d.principal=e.id","LEFT")
    	->join("department dp","d.parent_id=dp.id","LEFT")
    	->order("d.index,d.id")
    	->where($where)
    	->limit($pagestart,$lists)
    	->field("d.id,d.de_name,d.principal,e.id as em_id,e.em_name,dp.de_name as pde_name,d.remark,d.parent_id,d.index,d.is_sale")
    	->select();
    	

    	
    	return $arr;
    }
    //根据条件获取本条部门记录
    public function get_this_department($where){
		$arr=Db::table($this->table)->where($where)->find();
		return $arr;
    }
   

}
    
?>